home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / utils / stlogin4.lzh / WHO.C < prev    next >
C/C++ Source or Header  |  1993-05-13  |  1KB  |  63 lines

  1. /* Simple UNIX like who on ATARI ST. Kees Lemmens; Oktober 1992
  2.  
  3.    UTMP must exist and be maintained by getty.
  4.    
  5.    Any questions or suggestions about this program can be send to:
  6.    lemmens@dv.twi.tudelft.nl
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13. #include <utmp.h>
  14. #include <signal.h>
  15. #include "ux_misc.h"
  16.  
  17. void fatal(char *txt)
  18. {    fprintf(stderr,"WHO: %s\n",txt);
  19.     exit(1);
  20. }
  21.  
  22. void main(int argc,char *argv[]) 
  23. {    extern int utmp_fd;
  24.     int type=USER_PROCESS,cnt=0;
  25.     char *nam;
  26.     struct utmp *w;
  27.  
  28.     if(argc==3)
  29.         if(!strcmp(argv[1],"am"))
  30.         {    if((nam=getenv("LOGNAME")) != NULL)    puts(nam);
  31.             else                                puts("No idea !\n");
  32.             exit(0);
  33.         }
  34.     while(--argc>0)            /* parse options */
  35.     {    if(*argv[1]=='-')
  36.         {    switch(*(++argv[1]))
  37.             {    case 'l':    type=LOGIN_PROCESS; break;
  38.                 default:    fatal("Usage= who [-l] | [am i]");
  39.             }
  40.             ++argv;
  41.         }
  42.     }    
  43.     setutent();
  44.     
  45.     while((w=getutent()) != NULL)
  46.     {    if(w->ut_type == type)
  47.         {    if(Pkill(w->ut_pid,SIGNULL) == 0) /* process exists ? */
  48.             {    printf("%-8s %-*s %s",w->ut_user,(int)
  49.                 sizeof(w->ut_line),w->ut_line,ctime(&w->ut_time));
  50.                 cnt++;
  51.             }
  52.             else
  53.             {    w->ut_type=DEAD_PROCESS;
  54.                 setutent();    pututline(w);    /* correct UTMP entry */
  55.             }
  56.         }
  57.     }
  58.     if(cnt==0)
  59.         puts("No processes found\n");
  60.     endutent();
  61.     exit(0);
  62. }
  63.